import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutterapp/pages/category_page.dart';

//至少有两个页面，否则运行报错
import 'home_page.dart';
import 'category_page.dart';
// import 'cart_page.dart';
// import 'member_page.dart';

class IndexPage extends StatefulWidget{
  _IndexPageState  createState() => _IndexPageState();
}

//
class _IndexPageState extends State<IndexPage>{
  final List<BottomNavigationBarItem>bottomTabs = [
    BottomNavigationBarItem(
      icon: Icon(CupertinoIcons.home),
      label: 'Home',

      // title: Text('Home')
      // title: Text('Home') //首页
    ),

    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.bookmark),
        label: 'Catories'
        // title: Text('Catories') //分类
    ),

    // BottomNavigationBarItem(
    //     icon: Icon(CupertinoIcons.shopping_cart),
    //     label: 'Cart'
    //     // title: Text('Cart') //购物车
    // ),

    // BottomNavigationBarItem(
    //     icon: Icon(CupertinoIcons.person),
    //     label: 'My'
    //     // title: Text('My') //我的
    // ),
  ];


  final List tabBodies = [
    HomePage(),
    CategoryPage(),
    // CartPage(),
    // MemberPage(),
  ];

  int currentIndex = 0;
  var currentPage;

  @override
  void initState(){
    currentPage = tabBodies[currentIndex];
    super.initState();
  }

  @override
  Widget build(BuildContext context){
    return Scaffold(
      backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: currentIndex,
        items: bottomTabs,
        onTap: (index){
          setState(() {
            currentIndex = index;
            currentPage = tabBodies[currentIndex];
          });
        },
      ),
      body: currentPage,
    );
  }
}

